package unit9_10;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class testDemo3 {
    public static void main(String[] args) {
        Connection connect=null;
        Statement statement=null;
//        sql语句
        String showSql="select * from person;";//查
        String deleSql="delete from person where id=2;";//删除
//        获取数据库连接
        connect=JDBC_test2.getConn();
        try {
//        获取数据库操作对象
            statement=connect.createStatement();

            statement.execute(deleSql);//删除操作

            ResultSet resultSet=statement.executeQuery(showSql);//查询
            while(resultSet.next()){
                System.out.print(resultSet.getInt("id")+" ");
                System.out.print(resultSet.getString("name")+" ");
                System.out.print(resultSet.getInt("age")+" ");
                System.out.print(resultSet.getString("sex")+" ");
                System.out.println();
            }



        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
//                释放资源
                connect.close();
                statement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }
    }
}
